package com.jiuli_travel.attraction_service.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiuli_travel.attraction_service.mapper.EntertainmentProjectMapper;
import com.jiuli_travel.attraction_service.model.dto.entertainment_project.EntertainmentProjectInsertRequest;
import com.jiuli_travel.attraction_service.model.entity.EntertainmentProject;
import com.jiuli_travel.attraction_service.model.vo.EntertainmentProjectVO;
import com.jiuli_travel.attraction_service.service.IEntertainmentProjectService;
import com.jiuli_travel.user_service.model.vo.UserVO;
import com.jiuli_travel.utils.UserHolder;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 景点娱乐项目表 服务实现类
 * </p>
 *
 * @author jiuli
 * @since 2024-04-01
 */
@Service
public class EntertainmentProjectServiceImpl extends ServiceImpl<EntertainmentProjectMapper, EntertainmentProject> implements IEntertainmentProjectService {

    @Autowired
    private HttpServletRequest httpServletRequest;


    // 查询某个景点的项目基础信息
    @Override
    public void selectEntertainmentProjectByAttractionId(Long attractionId) {
        // 1. 查询所有关于该景点的项目信息
        List<EntertainmentProject> entertainmentProjectList = lambdaQuery()
                .eq(EntertainmentProject::getAttractionId, attractionId)
                .list();
        if(entertainmentProjectList.isEmpty()){
            return;
        }

        // 2. 转化数据格式？
        List<EntertainmentProjectVO> entertainmentProjectVOS = BeanUtil.copyToList(entertainmentProjectList, EntertainmentProjectVO.class);

        // 3. 封装各类相关业务的基础信息
        entertainmentProjectVOS
                .forEach(entertainmentProjectVO -> {
                    // 3.1 TODO 景点门票 （票务系统是个难点丫）

                    // 3.2

                });
    }

    // 发布个人 entertainmentProject
    @Override
    public void publishEntertainmentProject(EntertainmentProjectInsertRequest entertainmentProjectInsertRequest) {
        //图片信息不能为空
//        if(entertainmentProjectInsertRequest.getImages() == null){
//            return;
//        }

        //获取发布该景区项目的用户信息
        UserVO user = UserHolder.getUser();

        /**
         * 1. 对于 entertainmentProject表 进行处理
         */
        EntertainmentProject entertainmentProject = BeanUtil.copyProperties(entertainmentProjectInsertRequest, EntertainmentProject.class);
        entertainmentProject.setUserId(user.getId());
        //进行发布
        save(entertainmentProject);

        /**
         * TODO 对其他的附属内容进行处理
         */

    }

    // 删除个人 entertainmentProject
    @Override
    public void batchDelEntertainmentProject(List<Long> entertainmentProjectIds) {
        /**
         * 对 entertainmentProject 表进行处理
         */
        //构造删除条件
        LambdaQueryChainWrapper<EntertainmentProject> delWrapper = lambdaQuery()
                .in(!entertainmentProjectIds.isEmpty(), EntertainmentProject::getId, entertainmentProjectIds);
        boolean remove = remove(delWrapper);
        if(!remove) return;

        /**
         * TODO 对和 entertainmentProject 有依赖关系的东西进行清理
         */

        entertainmentProjectIds.forEach(entertainmentProjectId -> {
            /**
             * TODO 与该景区项目有关的评论信息进行清空 （也可以进行后续异步处理）
             */
        });
    }
}












